<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>ajax-post</title>
    <script src="jquery.js"></script>
</head>
<body>
        <form action="login" method="get" enctype="application/x-www-form-urlencoded">
            <input type="text" name="username" placeholder="请输入用户名"><br>
            <input type="password" name="password" placeholder="请输入密码">
            <button type="submit">登录</button>
        </form>
</body>
<script>
        //AJAX:Asynchronous javascript and xml
        // 异步的js和xml
        // 在不重载页面的条件下更新页面数据
        $('form').submit(function(ev){
    //      阻止默认时间发生
            ev.preventDefault();
            console.log('已经阻止默认事件发生');
            // 获取表单数据，自动将其转换成字符串序列对
            // name = value&name=value;
            var data = $(this).serialize();
            $.get('index.html', data,function(resData){  //请求成功的回调函数
                    
                }
            )
        })
    </script>
</html>